{% comment %}
/* Copyright 2010 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
{% endcomment %}
{% extends 'admin_base.html' %}
{% block content %}
{% if confirmation %}
<div class="success">Update Completed!</div>
{% endif %}
{% if message %}
<div class="message">{{message}}</div>
{% endif %}
{% if alert %}
<div class="alert">{{alert}}</div>
{% endif %}
{% if action %}
<br><br>
<form method="POST" enctype="multipart/form-data">
  {% ifequal action 'new' %}
  {{test.filename}}
  <h3>Upload File</h3>
  <div class="table">
    <div class="row">
      <div class="cell label">
        File:
      </div>
      <div class="cell input">
        <input
          type="file"
          name="data">
        <input
          type="submit"
          name="upload"
          value="Upload">
          <input
            type="submit"
            name="cancel"
            value="Cancel">
      </div>
    </div>
    <div class="row">
      <div class="cell label">
      </div>
      <div class="cell input">
        <span class="important">
          Note: Limit the file to 0.95 MB.
        </span>
      </div>
    </div>
  </div>
  {% else %}
  <h3>Edit File</h3>
  <div class="table">
    <div class="row">
      <div class="cell label">
        File:
      </div>
      <div class="cell input">
        {{media.name}} - {{media.size}} MB
        <input type="hidden" name="key" value="{{media.key}}">
      </div>
    </div>
    <div class="row">
      <div class="cell label">
        Title:
      </div>
      <div class="cell input">
        <input
          type="text"
          name="title" value="{{media.title}}">
      </div>
    </div>
    <div class="row">
      <div class="cell label">
        Caption:
      </div>
      <div class="cell input">
        <input
          type="text"
          name="caption" value="{{media.caption}}">
      </div>
    </div>
    <div class="row">
      <div class="cell label">
        <input
          type="submit"
          name="save"
          value="Save">
      </div>
      <div class="cell input">
        <input
          type="submit"
          name="done"
          value="Done">
          <input
            type="submit"
            name="cancel"
            value="Cancel">
        </div>
      </div>
    </div>
  {% endifequal %}
</form>
{% else %}
  <div id="new-post" style="float:left;">
    <a href="/admin/media?action=new" id="new-post-link">+ Upload Media</a>
  </div><br><br>
  <div class="table">
      <div class="row">
        <div class="cell th">Action</div>
        <div class="cell th">Type</div>
        <div class="cell th">Size (MB)</div>
        <div class="cell th">Name</div>
        <div class="cell th">Title</div>
        <div class="cell th">Uploader</div>
        <div class="cell th">Date</div>
      </div>
      {% for file in media %}
      <div class="row">
        <div class="cell">
          <a href="/admin/media?action=edit&key={{file.key}}">Edit</a> |
          <a href="/admin/media?action=delete&key={{file.key}}">Delete</a>
        </div>
        <div class="cell">{{file.content_type}}</div>
        <div class="cell">{{file.size}}</div>
        <div class="cell">
          <a href="/media/?key={{file.key}}">{{file.name}}</a>
        </div>
        <div class="cell">{{file.title|default_if_none:""}}</div>
        <div class="cell">{{file.uploader.nickname}}</div>
        <div class="cell">{{file.date|date:"Y/m/d"}}</div>
      </div>
      {% endfor %}
    </div>
{% endif %}

{% endblock %}